import { defineStore } from "pinia";


export const useCartStore = defineStore('cart', {

    //数据状态
    state: () => {
        return {
            name: '鲁花压榨葵花仁油5L',
            price: 19.8,
            count: 1
        }
    },

    //action用于修改数据
    actions:{
        changePrice(price:number){
            //
            this.price = price
        },
        // changeCart():void{
            
        // },
       

        plusCount(num:number){
            if(this.count<=0){
                return
            }
            // console.log("1  num",num)
            this.count += num;
        }
    },

    //类似于计算属性
    getters:{
        // amount(state){
        //     return (state.price * state.count).toFixed(2)
        // }

        amount():number{
            return Number((this.price * this.count).toFixed(2))
        }
    },
    persist: {
        enabled: true, // 这个配置代表存储生效，而且是整个store都存储
      }
})